package mo.tags.greedy;

public class L984 {

    public String strWithout3a3b(int a, int b) {
        if (a >= b) {
            return build(a, 'a', b, 'b');
        } else {
            return build(b, 'b', a, 'a');
        }
    }

    private String build(int maxCount, char maxChar, int minCount, char minChar) {
        int group = (maxCount + 1) / 2;
        StringBuilder[] builders = new StringBuilder[group];
        for (int i = 0; i < group; i++) {
            builders[i] = new StringBuilder();
        }
        for (int i = 0; i < group; i++) {
            if (i == group - 1) {
                for (int j = 0; j < maxCount; j++) {
                    builders[i].append(maxChar);
                }
            } else {
                builders[i].append(maxChar).append(maxChar);
                maxCount -= 2;
            }
            if (minCount > 0) {
                builders[i].append(minChar);
                minCount--;
            }
        }
        //b剩余的
        for (int i = 0; i < minCount; i++) {
            builders[i%group].append(minChar);
        }
        return String.join("", builders);
    }

    public static void main(String[] args) {
        L984 test = new L984();
        System.out.println(test.strWithout3a3b(4, 1));
    }
}
